<template>
	<view class="container">
		<view class="total_amount">
			<text class="amount">{{(parame.amount?parseFloat(parame.amount):0).toFixed(2)}}</text>
			<text>元</text>
		</view>
		<view class="from">
			<view class="from_item">
				<view class="item_input_box">
					<view class="item_type">
						总金额
					</view>
					<input disabled class="item_input text_r" placeholder="¥0.00" type="number" maxlength="6" v-model="parame.amount" >
					<view class="unit">
						元
					</view>
				</view>
			</view>
			<view class="from_item">
				<view class="item_input_box">
					<view class="item_type">
						数量
					</view>
					<input disabled class="item_input text_r" placeholder="输入红包个数" type="number" maxlength="6" v-model="parame.count" >
					<view class="unit">
						个
					</view>
				</view>
				<view class="info">
					本群共{{parame.count}}人
				</view>
			</view>
			<view class="from_item">
				<view class="item_input_box">
					<input disabled class="item_input" placeholder="好好学习，天天向上" type="number" maxlength="6" v-model="parame.info" >
				</view>
			</view>
			<view class="from_item">
				<view class="item_btn_box" @click="submit">
					<text>塞钱进红包</text>
				</view>
			</view>
		</view>
		<custom-modal :isShow="showMcModal" :content="content" title="温馨提示" :inp="false" :showCancel="showCancel" @cancel="()=>{showMcModal = false}" @ok="confirm" ></custom-modal>
	</view>
</template>

<script>
	import {
		distributeRedPacket,
		queryStudentCardBalance
	} from '../../../common/api/index.js';
	import {
		_showLoading,
		_showToast
	} from '../../../common/js/util.js'
	import customModal from "../../../components/custom-modal/custom-modal.vue";
	export default {
		components: {
			customModal,
		},
		data() {
			return {
				parame: {
					amount: '',
					count: '',
					info: ''
				},
				qunMsg:{
					num: 9
				},
				dept: {},
				profile: {},
				showMcModal: false,
				content: '',
				showCancel: false
				
			};
		},
		onLoad(options) {
			this.dept = JSON.parse(options.dept)
			this.parame.amount = this.dept.num * 5
			this.parame.count = this.dept.num
			console.log(this.dept)
		},
		methods: {
			submit(){
				this.showMcModal = true
				this.showCancel = true
				this.content = "即将在该群中发放" + this.dept.num + "个红包，总金额" + this.dept.num * 5 + "元，请确认";
				this.confirm = () => {
					this.showMcModal = false
					this.content = ''
					this._distributeRedPacket()
				}
			},
			async _distributeRedPacket(){
				uni.showLoading({
					title: "发放中...",
					mask: true
				})
				let s_userId = uni.getStorageSync("s_userId");
				const result = await queryStudentCardBalance({
					userId: s_userId,
					bindType: '0'
				})
				if(result.code != 0){
					_showToast('数据获取失败，请稍后重试')
					return
				}
				const profile = this.profile = result.data.students[0].students[0];
				const res = await distributeRedPacket({
					orgId: profile.orgId,
					deptId: this.dept.deptId
				})
				if(res.code == 0){
					uni.hideLoading()
					this.showMcModal = true
					this.showCancel = false
					this.content = res.data
					this.confirm = () => {
						this.showMcModal = false
						this.content = ''
						uni.navigateBack()
					}
				}else {
					uni.hideLoading()
					this.showMcModal = true
					this.showCancel = false
					this.content = res.msg
					this.confirm = () => {
						this.showMcModal = false
						this.content = ''
					}
				}
			},
			confirm(){}
		}
	}
</script>

<style lang="scss" scoped>

	.container{
		height: 100vh;
		width: 100vw;
		background-color: #f5f5f5;
	}
	.total_amount{
		padding: 100rpx 0 40rpx;
		text-align: center;
		// display: flex;
		// flex-direction: column;
		// justify-content: center;
		// align-items: center;
		.amount{
			font-size: 90rpx;
			font-weight: 900;
		}
	}
	.from{
		padding: 36rpx;
	}
	.from_item{
		margin: 36rpx 0;
		.item_btn_box, .item_input_box{
			width: 100%;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
			padding: 32rpx;
			border-radius: 24rpx;
			box-sizing: border-box;
		}
		.item_btn_box{
			color: #FFF;
			padding: 24rpx;
			margin-top: 64rpx;
			justify-content: center;
			background-color: #e54716;
			&:active{
				background-color: #cd3d10;
			}
		}
		.item_input_box{
			background-color: #FFF;
			input.item_input{
				flex: 1;
				&.text_r{
					text-align: right;
				}
			}
			
			.unit, .item_type{
				padding: 0 12rpx;
			}
		}
		.info{
			font-size: 20rpx;
			color: #ccc;
			padding: 6rpx 24rpx;
		}
	}
</style>
